package com.software.loginregister.databasesHelper;

import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.software.loginregister.entity.User;
import com.software.loginregister.entity.room.WorksCache;
import com.software.loginregister.entity.room.WorksRoom;

@Database(
        entities = {WorksCache.class, User.class, WorksRoom.class},
        version = 3,
        exportSchema = false  // 添加这行来禁用schema导出
)
public abstract class AppDatabase extends RoomDatabase {
    public abstract WorksCacheDao worksCacheDao();
    public abstract UserDao userDao();

    public abstract WorksDao worksDao(); // 添加 WorksDao

    private static volatile AppDatabase INSTANCE;
    public static AppDatabase getInstance(final Context context) {
        return getDatabase(context);
    }

    public static AppDatabase getDatabase(final Context context) {
        if (INSTANCE == null) {
            synchronized (AppDatabase.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(
                            context.getApplicationContext(),
                            AppDatabase.class,
                            "worksd_atabase"
                    )
                    .fallbackToDestructiveMigration()  
                    .build();
                }
            }
        }
        return INSTANCE;
    }
}
